<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php echo DESCRIPTION; ?>
<?php echo KEYWORD; ?>
<title><?php echo WEB_TITLE;?></title>
<link href="<?php echo  WEB_URL;?>/styles/style.css" rel="stylesheet" />
<link href="<?php echo  WEB_URL;?>/styles/ads.css" rel="stylesheet" />
<link type="text/css" href="<?php echo  WEB_URL;?>/styles/ui-lightness/jquery-ui-1.8rc2.custom.css" rel="stylesheet" />

<!-- StyleSheet Plugin-->

<link type="text/css" href="<?php echo  WEB_URL;?>/styles/vtip.css" rel="stylesheet" />

<link rel="stylesheet" href="<?php echo  WEB_URL;?>/styles/pagination.css" type="text/css" media="screen"/>
<link rel="stylesheet" type="text/css" href="<?php echo  WEB_URL;?>/styles/jquery.fancybox-1.3.4.css" media="screen" />

<script type="text/javascript" src="<?php echo  WEB_URL;?>/scripts/jquery/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="<?php echo  WEB_URL;?>/scripts/jquery/jquery-ui-1.8rc2.custom.min.js"></script>

<!-- Script Plugin -->

<script type="text/javascript" src="<?php echo  WEB_URL;?>/scripts/jquery/vtip.js"></script>

<script type="text/javascript" src="<?php echo  WEB_URL;?>/scripts/jquery/tab.js"></script>
<script type="text/javascript" src="<?php echo  WEB_URL;?>/scripts/jquery/pagination.js"></script>

<script type="text/javascript" src="<?php echo  WEB_URL;?>/scripts/jquery/fancybox/jquery.mousewheel-3.0.4.pack.js"></script>
<script type="text/javascript" src="<?php echo  WEB_URL;?>/scripts/jquery/fancybox/jquery.fancybox-1.3.4.pack.js"></script>

</head>

<body>
	<div class="page">
    
    	<?php require_once('../header.php');?>
        
        <div class="content">
        	<div id="wrap_top">
            	<div id="wrap_top_left">
                	<!--<div id="wrap_ads">                	 
                        <div id="wrap_728x90"></div>
                	</div>-->
   
                    <div class="tabs">
                          <a tab="#tab_edit_profile">ประกาศทั้งหมดของฉัน</a>        
                          <a tab="#tab_advertise">โฆษณาของฉัน</a>
                    </div>
            
                    <div id="tab_edit_profile" class="tab_page">
                    <?php 
						$sql = "SELECT
								  `products`.*, `products_img`.`img1`, `category`.`cat_name`
								FROM
								  `products` INNER JOIN
								  `products_img` ON `products`.`pid` = `products_img`.`pid` INNER JOIN
								  `category` ON `products`.`cat_id` = `category`.`cat_id`
								WHERE
								  `products`.`poster` = '".$_SESSION['usr']."'
								ORDER BY
								  `products`.`p_change_place` DESC, `products`.`p_create` DESC ";
                    	$get_post = $db->select_query($sql);
						$cout_post = $db->rows($get_post);
                    ?>
                    	 <a class="large button blue" href="<?php echo WEB_URL;?>/products/?m=post&p=select_cat">ลงประกาศฟรี!</a> <a class="large button blue" id="del_all_post">ลบประกาศที่เลือก</a>
                         
                         <?php
						  $per_page = 10;
						  $rsd = mysql_query($sql);
						  $count = mysql_num_rows($rsd);
						  $pages = ceil($count/$per_page)
						  ?>
                         <div id="container">

                            <div class="search-background">
                            </div>
                    
                            <div id="content"></div>
                        </div>
                        <div id="paging_button">
                            <ul>
                            <?php
                            //Show page links
                            for($i=1; $i<=$pages; $i++)
                            {
                                echo '<li id="'.$i.'">'.$i.'</li>';
                            }?>
                            </ul>
                        </div>
                        
                    	 
                    </div>
                    <div id="tab_advertise" class="tab_page">
                   	<?php
						$myads_sql 	= '	SELECT
										  `advertise`.*, `positions`.`position_name`, `category`.`cat_name`
										FROM
										  `advertise` INNER JOIN
										  `products` ON `advertise`.`pid` = `products`.`pid` INNER JOIN
										  `positions` ON `positions`.`id` = `advertise`.`position_id` INNER JOIN
										  `category` ON `category`.`cat_id` = `advertise`.`cat_id`
										WHERE
										  `products`.`poster` = "'.$_SESSION['usr'].'"';
						$myads_q 	= $db->select_query($myads_sql);
					?>
                    	<table border="0" cellpadding="2" cellspacing="2" id="list" width="100%">
                            <thead>
                                <tr>
                                    <th width="80">รหัสสินค้า</th>                
                                    <th width="100">หมวดหมู่</th>
                                    <th width="100">ตำแหน่ง</th>
                                    <th width="60">ระยะเวลาติดประกาศ</th>
                                    <th width="60">เริ่มต้น</th>
                                    <th width="60">สิ้นสุด</th>
                                    <th width="80">ราคา ฿</th>
                                    <th width="90">สถานะ</th>
                                <tr>
                            </thead>
                            <tbody>
                    <?php
						while($myads = $db->fetch($myads_q)){
					?>
                        
                                <tr>
                                    <td align="center"><strong><?php echo $myads['id'].'#'.$myads['pid'];?></strong></td>
                                    <td align="center"><?php ($myads['cat_name']=="")? print 'ทุกหมวด': print $myads['cat_name'];?></td>
                                    <td align="center"><?php echo $myads['position_name'];?></td>
                                    <td align="center"><?php echo $myads['ads_period'];?> เดือน</td>
                                    <td>
										<?php 
											$period = ($myads['ads_period']>3)?$myads['ads_period']+1:$myads['ads_period'];
											$start = (time()- ($period*2419200));
											echo date('d-m-Y',$start);
										?>
                                  	</td>
                                    <td><?php echo date('d-m-Y',$myads['ads_expire']);?></td>
                                    <td>
                                    	<strong>
                                            ราคา <b style="color:red;margin-right:20px;"><?php echo $myads['ads_price'];?>฿</b> <br/>
                                            ส่วนลด <b style="color:red;margin-right:20px;"><?php echo $myads['ads_discount'];?>%</b><br/> 
                                            รวม <b style="color:red;"><?php echo $myads['ads_total'];?>฿</b>
                                        </strong>
                                    </td>
                                    <td align="center">
										<?php   $myads['ads_status']==1? 
												print '<b style="color:green;">ทำงาน</b>':
												print '<b style="color:red;">กำลังตรวจสอบ</b>';
										?>
                                  	</td>
                                <tr>
					<?php	
						}
					?>
                    		</tbody>
                        </table>
                    </div>
                    <script type="text/javascript">
                    <!--
                    $.tabs('.tabs a'); 
                    //-->
                    </script>
                                    
                                                                
              	</div>
              	
              	<?php require('user_menu.php');?>
                
            </div>
            
            
        </div>
        
        <?php require_once('../footer.php');?>
        
    </div>
</body>
</html>